package lol.clann.bukkit.pluginboot.model.gui;

import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
 * @author pyz
 * @date 2018/6/30 下午10:17
 */
public class ClickAction<E extends InventoryClickEvent, S extends IconSupplier> {
    private View view;
    private E event;
    private Element<S> element;
    private int slotIndex;
    private Player player;
    private Inventory inventory;

    public ClickAction(View view, E event, Element<S> element, Inventory inventory, int slotIndex) {
        this.view = view;
        this.event = event;
        this.element = element;
        this.slotIndex = slotIndex;
        this.inventory = inventory;
        this.player = (Player) event.getWhoClicked();
    }

    @Nullable
    public ItemStack getCursor() {
        return event.getCursor();
    }

    /**
     * 获取点击格子的物品
     *
     * @return
     */
    @Nonnull
    public ItemStack getItem() {
        return inventory.getItem(slotIndex);
    }

    public Inventory getInventory() {
        return inventory;
    }

    public Player getPlayer() {
        return player;
    }

    public View getView() {
        return view;
    }

    public E getEvent() {
        return event;
    }

    public Element<S> getElement() {
        return element;
    }

    public int getSlotIndex() {
        return slotIndex;
    }
}
